package com.one.api.user.controller;

import com.one.api.common.controller.BaseController;
import com.one.api.common.msg.builder.EmailContentBuilder;
import com.one.api.common.msg.entity.StringMsg;
import com.one.api.common.msg.entity.body.EmailMsgBody;
import com.one.api.common.msg.entity.Msg;
import com.one.api.common.msg.sender.KafkaSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/msg")
public class MessageSenderController extends BaseController {
    @Autowired
    KafkaSender kafkaSender;

    @RequestMapping("/send")
    public String send(@RequestParam(value = "msg") String msg){
        kafkaSender.sendString(StringMsg.build(msg));
        return "发送了，请看日志";
    }

    @RequestMapping("/sendEmail")
    public String sendEmail(){
        EmailMsgBody emailMsgBody=new EmailMsgBody();
        emailMsgBody.setSubject("旺仔小站验证码");
        emailMsgBody.setToAddress("1329807351@qq.com");
        emailMsgBody.setContent(EmailContentBuilder.buildDVCodeHtmlContent("旺仔", "888888", "5"));
        kafkaSender.sendEmail(Msg.build(emailMsgBody));
        return "邮件发送了，请看日志";
    }
}
